package cn._2dland.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class TDGSinaOld extends HttpServlet {
	private static final String SINA_URL = "http://v.iask.com/v_play.php?vid=";
	//private static final Logger logger = Logger.getLogger("TDGSina");

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String vid = req.getParameter("vid");
		StringBuffer result = new StringBuffer();

		if(vid != null){
			URL url = new URL(SINA_URL + vid);
			HttpURLConnection conn = (HttpURLConnection)url.openConnection();
			conn.setRequestMethod("GET");
			conn.addRequestProperty("Host", "v.iask.com");
			conn.addRequestProperty("Referer", "v.iask.com");
			conn.setDoInput(true);
			conn.connect();

			if(conn.getResponseCode() == 200){
				InputStream is = conn.getInputStream();
				BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
				String line = null;
				while((line=br.readLine()) != null){
					result.append(line).append("\n");
				}
				br.close();
				is.close();
			}

			conn.disconnect();
		}

		resp.setContentType("text/xml; charset=UTF-8");
		resp.setCharacterEncoding("utf-8");
		resp.getWriter().print(result.toString());
	}
}
